1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gdk.GLContext; 26 27 private import gdk.Display; 28 private import gdk.DrawContext; 29 private import gdk.Surface; 30 private import gdk.c.functions; 31 public import gdk.c.types; 32 private import glib.ErrorG; 33 private import glib.GException; 34 private import gobject.ObjectG; 35 36 37 /** 38 * `GdkGLContext` is an object representing a platform-specific 39 * OpenGL draw context. 40 * 41 * `GdkGLContext`s are created for a surface using 42 * [method@Gdk.Surface.create_gl_context], and the context will match 43 * the characteristics of the surface. 44 * 45 * A `GdkGLContext` is not tied to any particular normal framebuffer. 46 * For instance, it cannot draw to the surface back buffer. The GDK 47 * repaint system is in full control of the painting to that. Instead, 48 * you can create render buffers or textures and use [func@cairo_draw_from_gl] 49 * in the draw function of your widget to draw them. Then GDK will handle 50 * the integration of your rendering with that of other widgets. 51 * 52 * Support for `GdkGLContext` is platform-specific and context creation 53 * can fail, returning %NULL context. 54 * 55 * A `GdkGLContext` has to be made "current" in order to start using 56 * it, otherwise any OpenGL call will be ignored. 57 * 58 * ## Creating a new OpenGL context 59 * 60 * In order to create a new `GdkGLContext` instance you need a `GdkSurface`, 61 * which you typically get during the realize call of a widget. 62 * 63 * A `GdkGLContext` is not realized until either [method@Gdk.GLContext.make_current] 64 * or [method@Gdk.GLContext.realize] is called. It is possible to specify 65 * details of the GL context like the OpenGL version to be used, or whether 66 * the GL context should have extra state validation enabled after calling 67 * [method@Gdk.Surface.create_gl_context] by calling [method@Gdk.GLContext.realize]. 68 * If the realization fails you have the option to change the settings of 69 * the `GdkGLContext` and try again. 70 * 71 * ## Using a GdkGLContext 72 * 73 * You will need to make the `GdkGLContext` the current context before issuing 74 * OpenGL calls; the system sends OpenGL commands to whichever context is current. 75 * It is possible to have multiple contexts, so you always need to ensure that 76 * the one which you want to draw with is the current one before issuing commands: 77 * 78 * ```c 79 * gdk_gl_context_make_current (context); 80 * ``` 81 * 82 * You can now perform your drawing using OpenGL commands. 83 * 84 * You can check which `GdkGLContext` is the current one by using 85 * [func@Gdk.GLContext.get_current]; you can also unset any `GdkGLContext` 86 * that is currently set by calling [func@Gdk.GLContext.clear_current]. 87 */ 88 public class GLContext : DrawContext 89 { 90 /** the main Gtk struct */ 91 protected GdkGLContext* gdkGLContext; 92 93 /** Get the main Gtk struct */ 94 public GdkGLContext* getGLContextStruct(bool transferOwnership = false) 95 { 96 if (transferOwnership) 97 ownedRef = false; 98 return gdkGLContext; 99 } 100 101 /** the main Gtk struct as a void* */ 102 protected override void* getStruct() 103 { 104 return cast(void*)gdkGLContext; 105 } 106 107 /** 108 * Sets our main struct and passes it to the parent class. 109 */ 110 public this (GdkGLContext* gdkGLContext, bool ownedRef = false) 111 { 112 this.gdkGLContext = gdkGLContext; 113 super(cast(GdkDrawContext*)gdkGLContext, ownedRef); 114 } 115 116 117 /** */ 118 public static GType getType() 119 { 120 return gdk_gl_context_get_type(); 121 } 122 123 /** 124 * Clears the current `GdkGLContext`. 125 * 126 * Any OpenGL call after this function returns will be ignored 127 * until [method@Gdk.GLContext.make_current] is called. 128 */ 129 public static void clearCurrent() 130 { 131 gdk_gl_context_clear_current(); 132 } 133 134 /** 135 * Retrieves the current `GdkGLContext`. 136 * 137 * Returns: the current `GdkGLContext` 138 */ 139 public static GLContext getCurrent() 140 { 141 auto __p = gdk_gl_context_get_current(); 142 143 if(__p is null) 144 { 145 return null; 146 } 147 148 return ObjectG.getDObject!(GLContext)(cast(GdkGLContext*) __p); 149 } 150 151 /** 152 * Gets the allowed APIs set via gdk_gl_context_set_allowed_apis(). 153 * 154 * Returns: the allowed APIs 155 * 156 * Since: 4.6 157 */ 158 public GdkGLAPI getAllowedApis() 159 { 160 return gdk_gl_context_get_allowed_apis(gdkGLContext); 161 } 162 163 /** 164 * Gets the API currently in use. 165 * 166 * If the renderer has not been realized yet, 0 is returned. 167 * 168 * Returns: the currently used API 169 * 170 * Since: 4.6 171 */ 172 public GdkGLAPI getApi() 173 { 174 return gdk_gl_context_get_api(gdkGLContext); 175 } 176 177 /** 178 * Retrieves whether the context is doing extra validations and runtime checking. 179 * 180 * See [method@Gdk.GLContext.set_debug_enabled]. 181 * 182 * Returns: %TRUE if debugging is enabled 183 */ 184 public bool getDebugEnabled() 185 { 186 return gdk_gl_context_get_debug_enabled(gdkGLContext) != 0; 187 } 188 189 /** 190 * Retrieves the display the @context is created for 191 * 192 * Returns: a `GdkDisplay` 193 */ 194 public override Display getDisplay() 195 { 196 auto __p = gdk_gl_context_get_display(gdkGLContext); 197 198 if(__p is null) 199 { 200 return null; 201 } 202 203 return ObjectG.getDObject!(Display)(cast(GdkDisplay*) __p); 204 } 205 206 /** 207 * Retrieves whether the context is forward-compatible. 208 * 209 * See [method@Gdk.GLContext.set_forward_compatible]. 210 * 211 * Returns: %TRUE if the context should be forward-compatible 212 */ 213 public bool getForwardCompatible() 214 { 215 return gdk_gl_context_get_forward_compatible(gdkGLContext) != 0; 216 } 217 218 /** 219 * Retrieves required OpenGL version. 220 * 221 * See [method@Gdk.GLContext.set_required_version]. 222 * 223 * Params: 224 * major = return location for the major version to request 225 * minor = return location for the minor version to request 226 */ 227 public void getRequiredVersion(out int major, out int minor) 228 { 229 gdk_gl_context_get_required_version(gdkGLContext, &major, &minor); 230 } 231 232 /** 233 * Used to retrieves the `GdkGLContext` that this @context share data with. 234 * 235 * As many contexts can share data now and no single shared context exists 236 * anymore, this function has been deprecated and now always returns %NULL. 237 * 238 * Deprecated: Use [method@Gdk.GLContext.is_shared] to check if contexts 239 * can be shared. 240 * 241 * Returns: %NULL 242 */ 243 public GLContext getSharedContext() 244 { 245 auto __p = gdk_gl_context_get_shared_context(gdkGLContext); 246 247 if(__p is null) 248 { 249 return null; 250 } 251 252 return ObjectG.getDObject!(GLContext)(cast(GdkGLContext*) __p); 253 } 254 255 /** 256 * Retrieves the surface used by the @context. 257 * 258 * Returns: a `GdkSurface` 259 */ 260 public override Surface getSurface() 261 { 262 auto __p = gdk_gl_context_get_surface(gdkGLContext); 263 264 if(__p is null) 265 { 266 return null; 267 } 268 269 return ObjectG.getDObject!(Surface)(cast(GdkSurface*) __p); 270 } 271 272 /** 273 * Checks whether the @context is using an OpenGL or OpenGL ES profile. 274 * 275 * Returns: %TRUE if the `GdkGLContext` is using an OpenGL ES profile 276 */ 277 public bool getUseEs() 278 { 279 return gdk_gl_context_get_use_es(gdkGLContext) != 0; 280 } 281 282 /** 283 * Retrieves the OpenGL version of the @context. 284 * 285 * The @context must be realized prior to calling this function. 286 * 287 * Params: 288 * major = return location for the major version 289 * minor = return location for the minor version 290 */ 291 public void getVersion(out int major, out int minor) 292 { 293 gdk_gl_context_get_version(gdkGLContext, &major, &minor); 294 } 295 296 /** 297 * Whether the `GdkGLContext` is in legacy mode or not. 298 * 299 * The `GdkGLContext` must be realized before calling this function. 300 * 301 * When realizing a GL context, GDK will try to use the OpenGL 3.2 core 302 * profile; this profile removes all the OpenGL API that was deprecated 303 * prior to the 3.2 version of the specification. If the realization is 304 * successful, this function will return %FALSE. 305 * 306 * If the underlying OpenGL implementation does not support core profiles, 307 * GDK will fall back to a pre-3.2 compatibility profile, and this function 308 * will return %TRUE. 309 * 310 * You can use the value returned by this function to decide which kind 311 * of OpenGL API to use, or whether to do extension discovery, or what 312 * kind of shader programs to load. 313 * 314 * Returns: %TRUE if the GL context is in legacy mode 315 */ 316 public bool isLegacy() 317 { 318 return gdk_gl_context_is_legacy(gdkGLContext) != 0; 319 } 320 321 /** 322 * Checks if the two GL contexts can share resources. 323 * 324 * When they can, the texture IDs from @other can be used in @self. This 325 * is particularly useful when passing `GdkGLTexture` objects between 326 * different contexts. 327 * 328 * Contexts created for the same display with the same properties will 329 * always be compatible, even if they are created for different surfaces. 330 * For other contexts it depends on the GL backend. 331 * 332 * Both contexts must be realized for this check to succeed. If either one 333 * is not, this function will return %FALSE. 334 * 335 * Params: 336 * other = the `GdkGLContext` that should be compatible with @self 337 * 338 * Returns: %TRUE if the two GL contexts are compatible. 339 * 340 * Since: 4.4 341 */ 342 public bool isShared(GLContext other) 343 { 344 return gdk_gl_context_is_shared(gdkGLContext, (other is null) ? null : other.getGLContextStruct()) != 0; 345 } 346 347 /** 348 * Makes the @context the current one. 349 */ 350 public void makeCurrent() 351 { 352 gdk_gl_context_make_current(gdkGLContext); 353 } 354 355 /** 356 * Realizes the given `GdkGLContext`. 357 * 358 * It is safe to call this function on a realized `GdkGLContext`. 359 * 360 * Returns: %TRUE if the context is realized 361 * 362 * Throws: GException on failure. 363 */ 364 public bool realize() 365 { 366 GError* err = null; 367 368 auto __p = gdk_gl_context_realize(gdkGLContext, &err) != 0; 369 370 if (err !is null) 371 { 372 throw new GException( new ErrorG(err) ); 373 } 374 375 return __p; 376 } 377 378 /** 379 * Sets the allowed APIs. When gdk_gl_context_realize() is called, only the 380 * allowed APIs will be tried. If you set this to 0, realizing will always fail. 381 * 382 * If you set it on a realized context, the property will not have any effect. 383 * It is only relevant during gdk_gl_context_realize(). 384 * 385 * By default, all APIs are allowed. 386 * 387 * Params: 388 * apis = the allowed APIs 389 * 390 * Since: 4.6 391 */ 392 public void setAllowedApis(GdkGLAPI apis) 393 { 394 gdk_gl_context_set_allowed_apis(gdkGLContext, apis); 395 } 396 397 /** 398 * Sets whether the `GdkGLContext` should perform extra validations and 399 * runtime checking. 400 * 401 * This is useful during development, but has additional overhead. 402 * 403 * The `GdkGLContext` must not be realized or made current prior to 404 * calling this function. 405 * 406 * Params: 407 * enabled = whether to enable debugging in the context 408 */ 409 public void setDebugEnabled(bool enabled) 410 { 411 gdk_gl_context_set_debug_enabled(gdkGLContext, enabled); 412 } 413 414 /** 415 * Sets whether the `GdkGLContext` should be forward-compatible. 416 * 417 * Forward-compatible contexts must not support OpenGL functionality that 418 * has been marked as deprecated in the requested version; non-forward 419 * compatible contexts, on the other hand, must support both deprecated and 420 * non deprecated functionality. 421 * 422 * The `GdkGLContext` must not be realized or made current prior to calling 423 * this function. 424 * 425 * Params: 426 * compatible = whether the context should be forward-compatible 427 */ 428 public void setForwardCompatible(bool compatible) 429 { 430 gdk_gl_context_set_forward_compatible(gdkGLContext, compatible); 431 } 432 433 /** 434 * Sets the major and minor version of OpenGL to request. 435 * 436 * Setting @major and @minor to zero will use the default values. 437 * 438 * The `GdkGLContext` must not be realized or made current prior to calling 439 * this function. 440 * 441 * Params: 442 * major = the major version to request 443 * minor = the minor version to request 444 */ 445 public void setRequiredVersion(int major, int minor) 446 { 447 gdk_gl_context_set_required_version(gdkGLContext, major, minor); 448 } 449 450 /** 451 * Requests that GDK create an OpenGL ES context instead of an OpenGL one. 452 * 453 * Not all platforms support OpenGL ES. 454 * 455 * The @context must not have been realized. 456 * 457 * By default, GDK will attempt to automatically detect whether the 458 * underlying GL implementation is OpenGL or OpenGL ES once the @context 459 * is realized. 460 * 461 * You should check the return value of [method@Gdk.GLContext.get_use_es] 462 * after calling [method@Gdk.GLContext.realize] to decide whether to use 463 * the OpenGL or OpenGL ES API, extensions, or shaders. 464 * 465 * Params: 466 * useEs = whether the context should use OpenGL ES instead of OpenGL, 467 * or -1 to allow auto-detection 468 */ 469 public void setUseEs(int useEs) 470 { 471 gdk_gl_context_set_use_es(gdkGLContext, useEs); 472 } 473 }